{# Render an easily styled classic pager #}
{% macro render(options, url) %}
  {% if ((options.page > 1) or (options.total > 1)) %}
    {% set pagerClass = options.class %}
    {% set gapClass = pagerClass + '__gap' if pagerClass else '' %}
    <div class="{{ pagerClass if pagerClass }}">
      {{ pagerPage(1, options, pagerClass, url) }}
      {% if apos.pager.showHeadGap(options) %}
        <span class="{{ gapClass }}">&hellip;</span>
      {% endif %}

      {% for page in apos.pager.pageRange({
        page: options.page,
        total: options.total,
        shown: options.shown or 5
      }) %}
        {{ pagerPageInner(page, options, pagerClass, url) }}
      {% endfor %}

      {% if apos.pager.showTailGap(options) %}
        <span class="{{ gapClass }}">&hellip;</span>
      {% endif %}
      {{ pagerPage(options.total, options, pagerClass, url) }}
    </div>
  {% endif %}
{% endmacro %}

{% macro pagerPageInner(page, options, pagerClass, url) %}
  {% if ((page > 1) and (page < options.total)) %}
    {{ pagerPage(page, options, pagerClass, url) }}
  {% endif %}
{% endmacro %}

{% macro pagerPage(page, options, pagerClass, url) %}
  {% set pageClass = pagerClass + '__item' if pagerClass else '' %}

  {% if (page <= options.total) %}
    <span class="{{ pageClass }}{% if page == 1 %}  is-first{% endif %}{% if page == options.total %} is-last{% endif %}{% if page == options.page %} is-active{% endif %}">
      {%- if (options.page != page) -%}
        <a href="{{ url | build({ page: page }) }}">
      {%- endif -%}
      {{ page }}
      {%- if (options.page != page) -%}
        </a>
      {%- endif -%}
    </span>
  {% endif %}
{% endmacro %}
